﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class AddNewWeightOfMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check user login or not
        if (Session["Username"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
            if (Session["RoleName"].ToString() == "Employee")
            {
                Response.Redirect("ValidateUser.aspx");
            }
    }
    protected void imgbAdd_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
        SqlCommand cmd = new SqlCommand("Insert into WeightOfMail (Weight, WeightCharge) values (@Weight, @WeightCharge)", cnn);

        cmd.Parameters.Add(new SqlParameter("@Weight", SqlDbType.NVarChar, 50));
        cmd.Parameters["@Weight"].Value = txtWName.Text;
        cmd.Parameters.Add(new SqlParameter("@WeightCharge", SqlDbType.Float));
        cmd.Parameters["@WeightCharge"].Value = txtWCharge.Text;

        cmd.ExecuteNonQuery();

        ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "ShowMessage()", true);
    }
    protected void imgbReset_Click(object sender, ImageClickEventArgs e)
    {
        txtWName.Text = "";
        txtWCharge.Text = "";
    }
    protected void imgbCancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("AdminHomePage.aspx");
    }
}